import request from '@/utils/request'

// 获取定时任务列表
export function fetchScheduleList(query) {
    return request({
        url: '/schedule/list',
        method: 'get',
        params: query
    })
}

// 创建定时任务
export function createSchedule(data) {
    return request({
        url: '/schedule',
        method: 'post',
        data
    })
}

// 更新定时任务
export function updateSchedule(data) {
    return request({
        url: '/schedule',
        method: 'put',
        data
    })
}

// 删除定时任务
export function deleteSchedule(id) {
    return request({
        url: `/schedule/${id}`,
        method: 'delete'
    })
}

// 刷新任务
export function refreshTask() {
    return request({
        url: '/schedule/refresh-tasks',
        method: 'post'
    })
}

// 刷新调度
export function refreshSchedule() {
    return request({
        url: '/schedule/refresh',
        method: 'post'
    })
}

// 改变任务状态
export function changeJobStatus(id, status) {
    return request({
        url: `/schedule/${id}/status`,
        method: 'put',
        data: { status }
    })
}

// 立即执行一次任务
export function runAJobNow(id) {
    return request({
        url: `/schedule/${id}/run`,
        method: 'post'
    })
} 